#include "fig_boss_attackmove_rightleft.h"
#include "fig_boss_attackmove_manager.h"
#include "fig_enemy_boss.h"

FIGBossAttackMoveRightLeft::FIGBossAttackMoveRightLeft(FIGBossAttackMoveManager* pManager) :
															FIGBossAttackMove(pManager),
															m_State(STATE_GOTO_CENTER)
{

}




void		FIGBossAttackMoveRightLeft::Tick(float dt)
{
	FIGEnemyBoss* pBoss = m_pManager->GetBoss();	
	if(!pBoss)
		return;

	FIGBossAttackMove::Tick(dt);

	if(m_Delay > 0)
		return;

	switch(m_State)
	{
		case STATE_GOTO_CENTER:
		{
			const float Diff = 0.5f - pBoss->m_Pos.x;
			
			if(Diff >= -0.025f && Diff <= 0.025f)
			{
				m_State = STATE_GO_RIGHT;
				m_Acceleration = 1.0f;
			}
			else if (Diff > 0)
				pBoss->m_Pos.x += m_Acceleration * dt;
			else
				pBoss->m_Pos.x -= m_Acceleration * dt;

			if(m_Acceleration > 0.3f)
				m_Acceleration -= dt;
		}
		break;

		case STATE_GO_RIGHT:
		{
			pBoss->m_Pos.x -= m_Acceleration * dt;
			if(m_Acceleration > 0.3f)
				m_Acceleration -= dt;
			if(pBoss->m_Pos.x < pBoss->m_Radius)
			{
				m_State = STATE_GO_LEFT;
				m_Acceleration  = 1.5f;
			}
		}
		break;

		case STATE_GO_LEFT:
		{

			pBoss->m_Pos.x += m_Acceleration * dt;	
			if(m_Acceleration > 0.3f)
				m_Acceleration -= dt;

			if(pBoss->m_Pos.x > 1.0f - pBoss->m_Radius)
			{
				m_State = STATE_GOBACK_CENTER; 
				m_Acceleration = 1.0f;
			}
			
		}
			break;
		
		case STATE_GOBACK_CENTER:
			{
			const float Diff = 0.5f - pBoss->m_Pos.x;
			
			if(Diff >= -0.025f && Diff <= 0.025f)
				m_pManager->End();
			else if (Diff > 0)
				pBoss->m_Pos.x += m_Acceleration * dt;
			else
				pBoss->m_Pos.x -= m_Acceleration * dt;	

			if(m_Acceleration > 0.3f)
				m_Acceleration -= dt;

			break;
			}

			default:
			break;

	};
	
}


void		FIGBossAttackMoveRightLeft::Start(float Delay)
{
	FIGBossAttackMove::Start(Delay);
	m_State = STATE_GOTO_CENTER;
	m_Acceleration = 1.0f;
}